import {
  /* eslint-disable no-unused-vars */
  Style,
  // form
  Checkbox,
  CheckboxGroup,
  Loading,
  Locale,
  Input,
  List,
  Radio,
  RadioGroup,
  TabBar,
  SearchBar,
  Select,
  Switch,
  Validator,
  Button,
  // popup
  CascadePicker,
  DatePicker,
  Popup,
  Picker,
  ToolBar,
  Noticebar,
  Card,
  IndexList,
  Navbar,
  Menu,
  TimeLine,
  TimeLineItem,
  Toast,
  Badge,
  Tag,
  Dialog,
  Table,
  ImagePicker,
  ImagePreview,
  EmptyStatus
} from './module';
import createAPI from './modules/CreateApi';
import {
  processComponentName
} from './common/helpers/util';

const components = [
  // form
  Loading,
  Locale,
  Checkbox,
  CheckboxGroup,
  Input,
  List,
  Radio,
  RadioGroup,
  TabBar,
  Select,
  SearchBar,
  Switch,
  Validator,
  Button,
  // popup
  CascadePicker,
  DatePicker,
  Popup,
  Picker,
  ToolBar,
  Noticebar,
  Card,
  IndexList,
  Navbar,
  Menu,
  TimeLine,
  TimeLineItem,
  Toast,
  Badge,
  Tag,
  Dialog,
  Table,
  ImagePicker,
  ImagePreview,
  EmptyStatus
];

function install(Vue) {
  if (install.installed) {
    return;
  }
  install.installed = true;
  components.forEach(Component => {
    Component.install(Vue);
  });
}

const Grimm = {
  /* eslint-disable no-undef */
  version: __VERSION__,
  install,
  // BScroll: BetterScroll,
  createAPI,
};

components.forEach(Component => {
  const name = processComponentName(Component, {
    firstUpperCase: true,
  });
  Grimm[name] = Component;
});

if (typeof window !== 'undefined' && window.Vue) {
  window.Vue.use(install);
}

export default Grimm;
